<?php

namespace app\common\model;

use think\Model;

class User extends Model
{
    // 通过手机号查看用户是否存在
    public function getUserByPhone($phoneNumber)
    {
        if (empty($phoneNumber)) {
            # code...
            return false;
        }

        $where = [
            'phone_number' => $phoneNumber
        ];

        $result = $this->where($where)->find();
        return $result;
    }

    // 如存在用户则更新数据即可
    public function upDataById($id, $data)
    {
        $where = [
            'id' => $id
        ];
        $user = $this->where($where)->find();
        $res = $user->save($data);
        return $res;
    }

    // 通过id获取用户数据
    public function getUserById($id)
    {
        $id = intval($id);

        if (!$id) {
            # code...
            return false;
        }

        return $this->find($id);
    }

    // 通过用户名查找用户
    public function getUserByusername($username)
    {
        if (empty($username)) {
            return false;
        }
        $where = [
            'username' => $username
        ];

        $result = $this->where($where)->find();
        return $result;
    }
}
